import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

@Entity("character_resources")
@ManualTimestamp()
export class CharacterResourcesEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "characterId", unique: true })
  characterId!: number;

  // 货币相关字段
  @Column("int", { default: 0, comment: "金币" })
  gold!: number;

  @Column("int", { default: 0, comment: "银两" })
  silver!: number;

  @Column("int", { default: 0, comment: "绑定银两" })
  bdSilver!: number;

  // 钱庄余额字段
  @Column("int", { default: 0, comment: "钱庄金币余额" })
  balanceGold!: number;

  @Column("int", { default: 0, comment: "钱庄银两余额" })
  balanceMoney!: number;

  // 特殊资源字段
  @Column("int", { default: 0, comment: "元宝" })
  fc!: number;

  @Column("int", { default: 0, comment: "超级元宝" })
  superHK!: number;

  @Column("int", { default: 0, comment: "铜钱" })
  tlz!: number;

  @Column("int", { default: 0, comment: "铜钱碎片" })
  tlzs!: number;

  @Column("int", { default: 0, comment: "VIP礼包" })
  vipBag!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @OneToOne(() => CharacterEntity, (character) => character.resources)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
